<template>
  <van-picker
    show-toolbar
    title="更新性别·"
    :columns="columns"
    :default-index="gender"
    @confirm="onConfirm"
    @cancel="onCancel"
  />
</template>

<script>
import { editUserProfileAPI } from '@/api'
export default {
  name: '',
  components: {},
  props: {
    gender: {
      type: [String, Number],
      required: true
    }
  },
  data() {
    return {
      columns: ['男', '女']
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    async onConfirm(value, index) {
      this.$toast.loading({
        message: '更新性别中...',
        forbidClick: true
      })
      try {
        await editUserProfileAPI({
          gender: index
        })
        this.$emit('update:gender', index)
        this.$emit('close')
        this.$toast.success('更新性别成功')
      } catch (error) {
        this.$toast.fail('更新性别失败！请重新修改')
      }
    },
    onCancel() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped lang="less"></style>
